package day03;
//练习
public class Day03HomeWork {
    public static void main(String[] args) {

        //1) +, -, *, /, %, ++, --
        int a =5, b=10, c=5, d=8, e=9, k=1, z=2;
        System.out.println("计算运算符");
        System.out.println(a+b+c+d+e);//37
        k--;
        z++;
        int f = a++;// a=(int)(a+1)
        int g = ++b;// b=(int)(b+1)
        System.out.println(k); //0
        System.out.println(z); //3
        System.out.println(a); //6
        System.out.println(b); //11
        System.out.println(f); //5
        System.out.println(g); //11
        System.out.println(b/6); //1
        System.out.println(d*e); //72
        System.out.println(a%5);//1
        System.out.println(c%f); //0
        System.out.println("-------");

        System.out.println("关系运算符");
        boolean a1 = a>b;
        System.out.println(a1); // 6>11, false
        System.out.println(g>=b); // 11=11, true
        System.out.println(d<=b); // 8<11, true
        System.out.println(g>f); // 11>5, true
        System.out.println(c<f); // 5=5, false
        System.out.println(a!=f); //6!=5, true
        System.out.println(a+b<d); // 6+11>8, false
        System.out.println(a%3<c); // 6/3<5, true
        System.out.println(k++>0); // 0=0,false k自增0变1
        System.out.println(z--<3); // 3=3, false z自减3变2
        System.out.println(z--<3); // 2<3, true  z自减2变1
        System.out.println(k);//1
        System.out.println(z);//1
        System.out.println("-------");

        System.out.println("逻辑运算符");
        // 与&&
        boolean a2 = a>b && b>c;
        System.out.println(a2); // false && true =false
        System.out.println(g>c && g<b); // true && false =false
        System.out.println(d>e && a+1>g); // false && false =false
        System.out.println(d!=b && c<b); // true && true =true
        // 或||
        System.out.println(g!=b || g>c); // false || true =true
        System.out.println(a<g || f>c); //  true || false = true
        System.out.println(e>c || d>=a); // true || true =true
        System.out.println(c!=f || g<d); // false &||false =false
        // 非!
        boolean b1 = !(a<b);
        System.out.println(b1);// !true=false
        System.out.println(!(a>b)); // !false=true
        // 与&&短路
        boolean b2 = a>b && c++>2;
        System.out.println(b2);// false
        System.out.println(c);//5, 短路 c++自增不执行
        // 或||短路
        boolean b3 = a<b || c++>2;
        System.out.println(b3);// true
        System.out.println(c);//5, 短路 c++自增不执行
        System.out.println("-------");

        System.out.println("赋值运算符");
        int h = 3;
         h *= 2;
        System.out.println(h);//6
        System.out.println(h/=4);//1
        System.out.println(h%=2);//1
        System.out.println(h+=5);//6
        System.out.println(h-=2);//4
        h+=2;
        System.out.println(h); //6
        h/=4;
        System.out.println(h); //1
        h*=8;
        System.out.println(h);//8

        short s = 5;
        //s = s + 10; //编译错误, 需要强转, 改为s=(short)(s+10)
        s += 10; // 相当于 s=(short)(s+10)
        System.out.println(s);//15
        System.out.println("-------");

        System.out.println("字符串连接");
        int st = 18;
        int sg = 16;
        int age = 20;
        System.out.println(sg+"连接"+18); // 16连接18
        System.out.println(sg+st+"18"+16);//341816
        System.out.println("16"+sg+16+st+18);//1616161818
        System.out.println("age="+age);//age=20
        System.out.println("我的年龄是"+age+"岁"); //我的年龄是20岁
        System.out.println("我今年"+age+"岁了");//我今年20岁了

        String name = "霍宇飞";
        System.out.println("name="+name);//name=霍宇飞
        System.out.println("大家好,我叫"+name);//大家好,我叫霍宇飞
        System.out.println("大家好,我叫"+name+",今年"+age+"岁了");//大家好,我叫霍宇飞,今年20岁了
        System.out.println("-------");

        System.out.println("条件运算符/三目运算符");
        int num = 5;
        int flag =num>5?1:0;
        System.out.println(flag);//0

        int m = 8, n=5;
        int max = m>n?n:m;
        System.out.println(max);//5
        System.out.println("-------");

        System.out.println("分级结构if");
        //满500打8折
        double price = 800.0; //消费金额
        if (price>=500){//判断 true/false
            price *= 0.8;//true, 打八折
        }
        System.out.println("最终消费金额:"+price);//最终消费金额为640.0

        double price2 = 400.0; //消费金额
        if (price2>=500){//判断 true/false
            price2 *= 0.8;//true, 打八折, false 不打折
        }
        System.out.println("最终消费金额:"+price2);//最终消费金额为400.0

        //判断成绩是否合法
        int score = 95; //合法区间0~100, 带数(95, -5,555)
        if (score>=0 && score<=100){//判断 true/false
            System.out.println("给成绩合法");//true
        }
        System.out.println("继续执行");//false
        System.out.println("-------");

        System.out.println("分支结构的练习 if else");
        //满500打8折,不满500打9折
        double price3 = 800.0; //带数(800.0, 400.0)
        if (price3>=500){
            price3 *= 0.8;
        }else {
            price3 *= 0.9;
        }
        System.out.println("最终消费金额为:"+price3);// 最终消费金额为:640

        //判断成绩合法
        int score2 = 95;//合法区间0~100, 带数(95, -5, 555)
        if(score2>=0 && score2<=100){
            System.out.println(score+"该成绩合法");
        }else {
            System.out.println(score+"该成绩不合法");
        }
        System.out.println("-------");

        System.out.println("分支结构练习 if...else if");
        //满4000,打五折, 满2000不满4000打七折, 满1000不满2000打八折,不满1000打九折
        double price4 = 8000.0;// 带数(4000.0, 3000.0)
        if (price4>=4000){
            price4 *= 0.5;
        }else if (price4>=2000){
            price4 *= 0.7;
        }else if (price4>=1000){
            price4 *= 0.8;
        }else {
            price4 *= 0.9;
        }
        System.out.println("您的最终消费金额为:"+price4);
    }
}
